﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShopOnline.Models.DAL
{
    public class DAL_PictureCatelogy
    {
        private ShopOnline.Models.ShopOnlineDBDataContext SC_DB;
        public DAL_PictureCatelogy()
        {
            SC_DB = new ShopOnlineDBDataContext();
        }


        public List<PictureCatelogy> getListPictureCatelogy()
        {
            return SC_DB.PictureCatelogies.ToList();
        }

        public List<PictureCatelogy> getListPictureCatelogyIsShow()
        {
            return (from c in SC_DB.PictureCatelogies where c.show == true select c).ToList();
        }

        public PictureCatelogy getPictureCatelogyById(int catelogyId)
        {
            return (from c in SC_DB.PictureCatelogies where c.pictureCatelogyId == catelogyId select c).FirstOrDefault();
        }

        public int CreatePictureCatlogy(PictureCatelogy cate)
        {
            int result = 0;
            try
            {
                SC_DB.PictureCatelogies.InsertOnSubmit(cate);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }

        public int EditCatlogy(PictureCatelogy cate)
        {
            int result = 0;
            try
            {
                var catelogy = (from c in SC_DB.PictureCatelogies where c.pictureCatelogyId == cate.pictureCatelogyId select c).FirstOrDefault();
                catelogy.title = cate.title;
                catelogy.curent = cate.curent;
                catelogy.description = cate.description;
                catelogy.imagePath = cate.imagePath;
                catelogy.show = cate.show;
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
        public int DeleteCatelogy(PictureCatelogy cate)
        {
            int result = 0;
            try
            {
                var catelogy = (from c in SC_DB.PictureCatelogies where c.pictureCatelogyId == cate.pictureCatelogyId select c).FirstOrDefault();
                SC_DB.PictureCatelogies.DeleteOnSubmit(catelogy);
                SC_DB.SubmitChanges();
                result = 1;
            }
            catch
            {

            }
            return result;
        }
    }
}